package com.bigdata.bookinfo.mapper;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class DateBookNumMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws InterruptedException, IOException {
        String[] line = value.toString().split("\t");
        String date = line[4];
        if (date!=null&&date.length()>4){
            date = date.substring(0, 4);
        }
        if (date==null||date.isEmpty()){
            return;
        }
        try {
            int integer = Integer.parseInt(date);
            if (integer>2023){
                return;
            }
        }catch (Exception e){
            return;
        }
        context.write(new Text(date+"年"),new IntWritable(1));
    }
}
